package com.bgs.service.impl;

import com.bgs.mapper.PunchMapper;
import com.bgs.pojo.Punch;
import com.bgs.pojo.PunchWay;
import com.bgs.service.PunchService;
import com.bgs.tool.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class PunchServiceImpl  implements PunchService {
    @Autowired
    private PunchMapper punchMapper;

    @Override
    public R selectall() {
        List<Punch> list =punchMapper.selectall();
        return R.ok().data("list",list);
    }

    @Override
    public R insert(Punch punch) {
        int ptype = 0;
        Date d=new Date();
        SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss");
        String ds=df.format(d);
        String Time1=new String("09:30:00");
        String Time2=new String("12:00:00");
        String Time3=new String("18:00:00");
        Integer a1=ds.compareTo(Time1);
        Integer a2=ds.compareTo(Time2);
        Integer a3=ds.compareTo(Time3);
        if (a1<0){
            punch.setPtype(ptype);
            System.out.println("早安，打工人");
        }else {
            if (a1>0&&a2<0){
                ptype = 1;
                punch.setPtype(ptype);
                System.out.println("你迟到了");
            }else {
                if (a2>0&&a3<0){
                    ptype = 3;
                    punch.setPtype(ptype);
                    System.out.println("你居然敢早退");
                }else {
                    System.out.println("下班了，打工人");
                }
            }
        }
        int i =punchMapper.insert(punch);
        return R.ok().data("i",i);
    }

    @Override
    public R getDays() {
        int i = punchMapper.getDays();
        return R.ok().data("i",i);
    }

    @Override
    public R getLate() {
        int i = punchMapper.getLate();
        return R.ok().data("i",i);
    }

    @Override
    public R getEarly() {
        int i = punchMapper.getEarly();
        return R.ok().data("i",i);
    }

    @Override
    public R getSelectTime(String ptime) {
        List<Punch> list = punchMapper.getSelectTime(ptime);
        return R.ok().data("list",list);
    }

    @Override
    public R pwSelect() {
        List<PunchWay> list = punchMapper.pwSelect();
        return R.ok().data("list",list);
    }

    @Override
    public R pwdelect(Integer pwid) {
        int i = punchMapper.pwdelect(pwid);
        return R.ok().data("i",i);
    }

    @Override
    public R pwupdate(PunchWay punchWay) {
        int i = punchMapper.pwupdate(punchWay);
        return R.ok().data("i",i);
    }

    @Override
    public R pwadd(PunchWay punchWay) {
        int i = punchMapper.pwadd(punchWay);
        return R.ok().data("i",i);
    }
}
